<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
</body>
<script src="../js/task2.js">
    //使用原型方法以及正则表达式清除字符串空格
    let str = " kgc sss "
    //去除前面的空格
    String.prototype.trims = function () {
        return this.replace(/^\s+/g, "")
    }
    console.log(str.trims());
    //去除后面的空格
    String.prototype.trims1 = function () {
        return this.replace(/\s+$/g, "")
    }

    console.log(str.trims1());
    //去除前后的空格
    String.prototype.trims2 = function () {
        return this.trim()
    }
    console.log(str.trims2())
    //去除所有的空格
    String.prototype.trims3 = function () {
        return this.replace(/\s+/g, "")

    }
    console.log(str.trims3())
</script>

</html>